﻿[
	// Define the CMS type
	Define_Type: 'shp_CMS';
		
		
		Local:'pageid';
		Local:'title';
		Local:'content';
		Local:'lang';
		Local:'metakeywords';
		Local:'metadesc';
			
		Define_Tag:'oncreate';
		/Define_Tag;
		
		
		
	// *******************************************
	// ** PAGES                                 **
	// *******************************************

		Define_Tag:'getPage', -Required='page', -EncodeNone;
			Self->'pageid'= #page;

			var:'sql_pages'='	SELECT		*
								FROM 		SHb_pages
								INNER JOIN	SHb_translations_pages ON SHb_translations_pages._k2_pageid = SHb_pages._k1_pageid
								INNER JOIN	SHb_languages ON SHb_languages._k1_languageid = SHb_translations_pages._k2_languageid
								WHERE 		SHb_languages.language = \'' + $mylang + '\'';

			If:(#page)!='';
				$sql_pages+='	AND			SHb_pages._k1_pageid = \'' + (#page) +'\'';
			else;
				$sql_pages+='	AND			SHb_pages._k1_pageid = 1';
			/if;
			
			inline: -database='shoebox', -sql=$sql_pages;
				if:(found_count)!=0;
					local:'myTitle' = (field:'Page_title');
					local:'myContent' = (field:'Page_content');
					local:'myMetaKeywords' = (field:'meta_keywords');
					local:'myMetaDesc' = (field:'meta_description');

				else;
					local:'myTitle' = 'Error: Page not found';
					local:'myContent' = '';
					local:'myMetaKeywords' = '';
					local:'myMetaDesc' = '';

				/if;
			/inline;
	
			Self->'title' 		 = #myTitle;
			Self->'content' 	 = #myContent;
			Self->'metakeywords' = #myMetaKeywords;
			Self->'metadesc'	 = #myMetaDesc;
		/Define_Tag;
		
		Define_Tag:'CMSPageTitle'; 
			Return: Self->'title';
		/Define_Tag;
		
		Define_Tag:'CMSPageContent'; 
			Return: Self->'content';
		/Define_Tag;
		
		Define_Tag:'CMSPageID'; 
			Return: Self->'pageid';
		/Define_Tag;
		
		Define_Tag:'CMSPageMetaKeywords'; 
			Return: Self->'metakeywords';
		/Define_Tag;
		
		Define_Tag:'CMSPageMetaDescription'; 
			Return: Self->'metadesc';
		/Define_Tag;
			

	// *******************************************
	// ** MENUS                                 **
	// *******************************************
		
		Define_Tag:'getMenu', -Optional='menu', -EncodeNone;
			Local:'output' = '';

			var:'sql_menus'='	SELECT		*
            					FROM 		SHb_menus
            					INNER JOIN	SHb_translations_menus ON SHb_translations_menus._k2_menuid = SHb_menus._k1_menuid
            					INNER JOIN	SHb_languages ON SHb_languages._k1_languageid = SHb_translations_menus._k2_languageid
            					WHERE 		SHb_languages.language = \'' + $mylang + '\'
            					AND			SHb_menus.active = 1
            					ORDER BY	SHb_menus._k2_parentid, SHb_menus._k2_levelid, SHb_menus._k1_menuid';

			
			inline: -database='shoebox', -sql=$sql_menus;
				if:(found_count)!=0;
					
					#output += '<ul>';
				
					Records;
						#output += '<li><a href="' + ($CMS_linkbaseurl) + '" target="' + (field:'target_window') + '">' + (field:'label') + '</a></li>';
					/Records;
					
					#output += '</ul>';

				/if;
			/inline;
			
			
			Return(#output);

		/Define_Tag;
		

		
		
	// *******************************************
	// ** LANGUAGES                             **
	// *******************************************

		Define_Tag: 'getLang', -Optional='l', -EncodeNone;
				If:(#l)!='';
					var('language')=(#l);
				Else;
					var('language')=$CMS_defaultlanguage;
				/if;			
		/Define_Tag;
		
		Define_Tag: 'getLangNav', -optional='l', -EncodeNone;

				inline: -database='shoebox', -sql='SELECT * FROM SHb_languages';
					var:'taallijst'=(array);
					if:(error_currenterror:-errorcode)==0;
						Records;
							$taallijst->(Insert:(field:'language'));
						/Records;
					/if;
				/inline;
			
				Local:'taallijst' = $taallijst;
				Local:'currentlang' = (var:'language');
				Local:'output' = '';
				iterate: (#taallijst), (var:'thislang');
					#output += '<li>';
					if:($thislang)==(#currentlang);
						#output += '<a href="' + ($CMS_linkbaseurl) + '?l=' + $thislang + '" class="current">';
					else;
						#output += '<a href="' + ($CMS_linkbaseurl) + '?l=' + $thislang + '">';
					/if;
					#output += $thislang;
					#output += '</a></li>';
				/iterate;
				Return(#output);
			
		/Define_Tag;
		
		
		
	
	// *******************************************
	// ** TREE                                  **
	// *******************************************
		
		
		Define_Tag:'getTree', -EncodeNone;
			Local:'output' = '';
			
			#output += '<ul id="tree">';
           						Records: -InlineName='Get_home_menu';
            #output += '			<li><a href="' +(Response_FilePath) + '?p=' + (field:'_k2_pageid') + '&l=' $mylang + '" id=\"dontShow\">' + (field:'label') + '</a></li>';
								/Records;
								Records: -InlineName='Get_top_menus';
									if: (field:'_k2_pagetypeid')==2 && (field:'target_url')!='';
			#output += '				<li><a href="' + (field:'target_url') + '" target="'+ (field:'target_window') +'">' + (field:'label') + '</a></li>';
									else: (field:'_k2_pagetypeid')==1;
			#output += '				<li><a href="' + (Response_FilePath) +'?p=' + (field:'_k2_pageid') + '&l=' + $mylang + '" id=\"' + (field:'_k2_pageid') + '\">' + (field:'label') + '</a>';
									/if;
										var:'current_menu_id'=(field:'_k1_menuid');
			   							var:'sql_sub_menus'='
											SELECT		*
											FROM 		SHb_menus
											INNER JOIN	SHb_translations_menus ON SHb_translations_menus._k2_menuid = SHb_menus._k1_menuid
											INNER JOIN	SHb_languages ON SHb_languages._k1_languageid = SHb_translations_menus._k2_languageid
											WHERE 		SHb_languages.language = \'' + $mylang + '\'';
			$sql_sub_menus += '				AND			SHb_menus.active = 1 
											AND			SHb_menus._k2_parentid = \'' + $current_menu_id + '\'';
			$sql_sub_menus += '				ORDER BY	SHb_menus._k2_parentid, SHb_menus._k1_menuid';
										Inline: -database='SHoebox', -sql=$sql_sub_menus;
											if:(found_count)!=0;
			#output += '						<ul>';
													Records;
														if: (field:'_k2_pagetypeid')==2 && (field:'target_url')!='';
			#output += '									<li><a href="' + (field:'target_url') + '" target="'+ (field:'target_window') +'">' + (field:'label') + '</a></li>';
														else: (field:'_k2_pagetypeid')==1;
			#output += '									<li><a href="' + (Response_FilePath) + '?p=' + (field:'_k2_pageid') + '&l=' + $mylang + '" id=\"' + (field:'_k2_pageid') + '\">' + (field:'label') + '</a></li>';
														/if;
													/Records;
			#output += '						</ul>';
											/if;
			 							/Inline;
			#output += '			</li>';
								/Records;
			#output += '	</ul>';
			#output += '	<br /><br />';
			

			Return(#output);

		/Define_Tag;
	
		
	
		
	/Define_Type;
]